package org.xiaojl.xcloud.tools.gateway.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericToStringSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**  
 * <p>Title: RedisConfig</p>  
 *
 * <p>Description: 服务集群限流的数据存放到redis中</p>  
 *
 * @author jilong.xiao  
 * @date 2018年5月7日  
 */
@Configuration
public class RedisConfig {
	@Autowired
	JedisConnectionFactory jedisConnectionFactory;
	
	@Bean(name="longRedisTemplate")
	public RedisTemplate<String,Long> redisTemplate(){
		RedisTemplate<String,Long> rt = new RedisTemplate<String,Long>();
		rt.setConnectionFactory(jedisConnectionFactory);
		rt.setKeySerializer(new StringRedisSerializer());
		rt.setHashValueSerializer(new GenericToStringSerializer< Long >( Long.class ) );
		rt.setValueSerializer(new GenericToStringSerializer< Long >( Long.class ) );
		return rt;
	}
}
